#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
typedef struct QueueNode
{
	int data;
	struct QueueNode* next;
}QNode;
typedef struct Queue
{
	QNode* head;
	QNode* tail;
	int size;
}Queue;
void QueueInit(Queue* p)
{
	assert(p);
	p->head = NULL;
	p->tail = NULL;
	p->size = 0;
}
void QueueDestory(Queue* p)
{
	assert(p);
	QNode* scout = p->head;
	while (scout != NULL)
	{
		QNode* nextnode = scout->next;
		free(scout);
		scout = nextnode;
	}
	p->head = p->tail = NULL;
	p->size = 0;
}
void QueuePush(Queue* p,int x)
{
	assert(p);
	QNode* newnode = (QNode*)malloc(sizeof(Queue));

	newnode->data= x;
	newnode->next = NULL;
	if(p->tail == NULL)
	{
		p->tail = p->head = newnode;
	}
	else
	{
		p->tail->next = newnode;
		p->tail = p->tail->next;
	}
	p->size++;
}
void QueuePop(Queue* p)
{
	assert(p->head);
	assert(p);
	if (p->head->next == NULL)
	{
		free(p->head);
		p->head = p->tail = NULL;
		return;
	}
	Queue* nextnode = p->head->next;
	free(p->head);
	p->head = nextnode;
	p->size--;
}
int QueueFront(Queue* p)
{
	assert(p);
	assert(p->head);

	return p->head->data;
}
int QueueBack(Queue* p)
{
	assert(p);
	assert(p->tail);
	
	return p->tail->data;
}
int QueueSize(Queue* p)
{
	assert(p);
	assert(p->head);

	return p->size;
}
int QueueEmpty(Queue* p)
{
	return p->head == NULL && p->tail == NULL;
}
int main()
{
	Queue p;
	QueueInit(&p);
	QueuePush(&p, 1);
	QueuePush(&p, 2);
	QueuePush(&p, 3);
	QueuePush(&p, 4);
	printf("%d",QueueSize(&p));
}